/*----------------------------------------
	1.1.2) 页面编辑
	----------------------------------------*/
	var Admin;
	if (!Admin) Admin = {};
	Admin.ep = {};

	/**
	 * main gui of edit page
	 */
	Admin.ep.main = function()
	{
		$(".content_block").spin();
		$.ajax({
			url: ep_path + "main",
			success: function(html) {
				$(".content_block").spin(false);
				$(".content_block").html(html);
			}
		});
	}
	
	/**
	 * society festival page setting form
	 */
	Admin.ep.sfp_setting_form = function()
	{
		$(".content_block").spin();
		$.ajax({
			url: ep_path + "sfp_setting_form",
			success: function(html) {
				$(".content_block").spin(false);
				$(".content_block").html(html);
			}
		});
	}
	
	/**
	 * society festival page setting submit
	 * @param society_festival_setting_array
	 */
	Admin.ep.sfp_setting_submit = function(society_festival_setting_array)
	{
		$(".content_block").spin();
		$.ajax({
			url: ep_path + "sfp_setting_submit",
			dataType: 'json',
			data: {society_festival_setting_array: society_festival_setting_array},
			success: function(data) {
				$(".content_block").spin(false);
				$(".message").css({ "display": "none" });
				if (data == 'succeed') {
					$(".message.success").css({ "display": "block" });
				}
			}
		});
	}
	
	/**
	 * static page setting form
	 */
	Admin.ep.sp_setting_form = function()
	{
		$(".content_block").spin();
		$.ajax({
			url: ep_path + "sp_setting_form",
			success: function(html) {
				$(".content_block").spin(false);
				$(".content_block").html(html);
			}
		});
	}
	
	/**
	 * static page setting submit
	 * @param static_page_setting_array
	 */
	Admin.ep.sp_setting_submit = function(static_page_setting_array)
	{
		$(".content_block").spin();
		$.ajax({
			url: ep_path + "sp_setting_submit",
			dataType: 'json',
			data: {static_page_setting_array: static_page_setting_array},
			success: function(data) {
				$(".content_block").spin(false);
				$(".message").css({ "display": "none" });
				if (data == 'succeed') {
					$(".message.success").css({ "display": "block" });
				}
			}
		});
	}
	
	/**
	 * public ckfinder api
	 */
	Admin.ep.ckfinder_browse_server = function()
	{
		var finder = new CKFinder();
		finder.selectActionFunction = set_file_field;
		finder.popup();
	}
	function set_file_field(fileUrl) {
		$(".xFilePath").val(fileUrl);
	}
	
	// listen to sfp (society festival page) setting submit
	$(".sfp#setting_submit").live('click', function() {
		var is_empty = 0;
		$(":text").each(function() {
			if ($(this).val() == '') {
				alert("请将设置信息填写完整");
				is_empty = 1;
				return false;
			}
		});
		
		if (is_empty == 1) { return; }
		
		var society_festival_setting_array = new Array();
		$(":text").each(function() {
			society_festival_setting_array[$(this).attr("id")] = $(this).val();
		});
		
		Admin.ep.sfp_setting_submit(society_festival_setting_array);
		setTimeout("$('.message').slideUp(200)", 3000);
	});
	
	// listen to sfp video preview
	$(".sfp#video_preview").live('click', function() {
		$(".content_block").append(
			"<div class='sfp' id='video_preview_dialog' title='文化节视频预览'>" +
			$("#0").val() +
			"</div>"
		);
		$("#dialog:ui-dialog").dialog("destroy");
		
		$(".sfp#video_preview_dialog").dialog({
			show: "blind",
			hide: "explode",
			resizable: false,
			draggable: false,
			width: 512,
			height: 509,
			modal: true,
			buttons: {
				"关闭窗口": function() {
					$( this ).dialog( "close" );
				}
			}
		});
	});
	
	// listen to sfp banner preview
	$(".sfp#banner_preview").live('click', function() {
		$(".content_block").append(
			"<div class='sfp' id='banner_preview_dialog' title='站点首页文化节Banner预览'>" +
			"<img src='" + $("#1").val() + "'>" +
			"</div>"
		);
		$("#dialog:ui-dialog").dialog("destroy");
		
		$(".sfp#banner_preview_dialog").dialog({
			show: "blind",
			hide: "explode",
			resizable: false,
			draggable: false,
			width: 930,
			height: 320,
			modal: true,
			buttons: {
				"关闭窗口": function() {
					$( this ).dialog( "close" );
				}
			}
		});
	});
	
	// listen to sfp banner upload
	$(".sfp#banner_upload").live('click', function() {
		$(".content_block").spin();
		$.ajax({
			url: ep_path + "set_ckfinder_session",
			dataType: 'json',
			data: {session: "index_banner"},
			success: function(data) {
				$(".content_block").spin(false);
				Admin.ep.ckfinder_browse_server();
			}
		});
	});
	
	// listen to sp (static page) setting submit
	$(".sp#setting_submit").live('click', function() {
		var is_empty = 0;
		$(":text").each(function() {
			if ($(this).val() == '') {
				alert("请将设置信息填写完整");
				is_empty = 1;
				return false;
			}
		});
		
		if (is_empty == 1) { return; }
		
		var static_page_setting_array = new Array();
		
		$(":text").each(function() {
			var a = $(this).attr("id").split('_')[0];
			var b = $(this).attr("id").split('_')[1];
			
			if (!static_page_setting_array[a]) {
				static_page_setting_array[a] = new Array();
			}
			static_page_setting_array[a][b] = $(this).val();
		});
		
		Admin.ep.sp_setting_submit(static_page_setting_array);
		setTimeout("$('.message').slideUp(200)", 3000);
	});
	
	// listen to sp banner preview
	$(".sp#banner_preview").live('click', function() {
		
		$(".content_block").append(
			"<div class='sp' id='banner_preview_dialog' title='站点首页静态网页Banner预览'>" +
			"<img src='" + $($(this).parent().children().first()).val() + "'>" +
			"</div>"
		);
		$("#dialog:ui-dialog").dialog("destroy");
		
		$(".sp#banner_preview_dialog").dialog({
			show: "blind",
			hide: "explode",
			resizable: false,
			draggable: false,
			width: 930,
			height: 320,
			modal: true,
			buttons: {
				"关闭窗口": function() {
					$( this ).dialog( "close" );
				}
			}
		});
	});
	
	// listen to sp banner upload
	$(".sp#banner_upload").live('click', function() {
		$(".content_block").spin();
		$(".input-flex").removeClass("xFilePath");
		$($(this).parent().children().first()).addClass("xFilePath");
		$.ajax({
			url: ep_path+ "set_ckfinder_session",
			dataType: 'json',
			data: {session: "index_banner"},
			success: function(data) {
				$(".content_block").spin(false);
				Admin.ep.ckfinder_browse_server();
			}
		});
	});
	
	// listen to sp file preview
	$(".sp#file_preview").live('click', function() {
		
		$(".content_block").append(
			"<div class='sp' id='file_preview_dialog' title='站点静态网页预览'>" +
			"<iframe style='overflow:hidden;' src='" + $($(this).parent().children().first()).val() + "' width='100%' height='100%'>" +
			"</div>"
		);
		$("#dialog:ui-dialog").dialog("destroy");
		
		$(".sp#file_preview_dialog").dialog({
			show: "blind",
			hide: "explode",
			resizable: false,
			draggable: false,
			width: 1080,
			height: 700,
			modal: true,
			buttons: {
				"关闭窗口": function() {
					$( this ).dialog( "close" );
				}
			}
		});
	});
	
	// listen to sp file upload
	$(".sp#file_upload").live('click', function() {
		$(".content_block").spin();
		$(".input-flex").removeClass("xFilePath");
		$($(this).parent().children().first()).addClass("xFilePath");
		$.ajax({
			url: ep_path + "set_ckfinder_session",
			dataType: 'json',
			data: {session: "static_page"},
			success: function(data) {
				$(".content_block").spin(false);
				Admin.ep.ckfinder_browse_server();
			}
		});
	});
	
	